package db;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class SQLListReader {

    private SQLListReader() {
    }

    /**
     * Read the SQL script file names from the specified properties file.
     * 
     * @param listFile
     *            Full path to the properties file containing the list of SQL
     *            script (.sql) files.
     * @return A list of SQL script file names.
     * @throws IOException
     */
    public static String[] readFromFile(File listFile) throws IOException {

        BufferedReader reader = new BufferedReader(new FileReader(listFile));
        List<String> listOfSQLScripts = new ArrayList<String>();

        String line = null;

        while (null != (line = reader.readLine())) {
            line = line.trim();
            if ((line.length() == 0)) {
                continue; // omit blank lines
            }
            if (line.startsWith("--")) {
                continue; // omit comment lines
            }
            listOfSQLScripts.add(line);
        }

        return (String[]) listOfSQLScripts.toArray(new String[0]);
    }
}
